//
//  BootPageViewController.m
//  huashiedu
//
//  Created by oceans on 2018/9/17.
//  Copyright © 2018年 hema. All rights reserved.
//

#import "BootPageViewController.h"

@interface BootPageViewController () <UIScrollViewDelegate>

@end

@implementation BootPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setup];
}

- (void)setup {
    
    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    scroll.backgroundColor = [UIColor whiteColor];
    scroll.pagingEnabled = YES;
    scroll.delegate = self;
    scroll.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:scroll];
    
    for (int i = 0; i < 3; i ++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth * i, 0, ScreenWidth, ScreenHeight)];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"boot_%d", i]];
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        imageView.layer.masksToBounds = YES;
        [scroll addSubview:imageView];
    }
    
    scroll.contentSize = CGSizeMake(ScreenWidth * 3, ScreenHeight);
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 200, 130);
    button.center = CGPointMake(ScreenWidth * 2.5, ScreenHeight * 0.77);
    [button addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
    [scroll addSubview:button];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    
    if (scrollView.contentOffset.x + ScreenWidth - 70 > scrollView.contentSize.width) {
        [self close];
    }
}

- (void)close {
    [self dismissViewControllerAnimated:NO completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
